package com.zxy.salenet.web.service.imple;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zxy.salenet.web.mapper.SalenetUserMapper;
import com.zxy.salenet.web.pojo.SalenetUser;
import com.zxy.salenet.web.service.AdminUserOperationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: zxy
 * @version: 1.0
 * @description: 管理员对用户操作接口实现
 */
  /**
 * AdminUserOperationServiceImpl
 */
@Service
public class AdminUserOperationServiceImpl implements AdminUserOperationService {
    @Autowired
    private SalenetUserMapper userMapper;
    /**
     * 获取用户信息
     *
     * @param userName 用户名
     * @param pageNum  当前页数
     * @param pageSize 总页数
     * @return
     */
    @Override
    public PageInfo<SalenetUser> querAllUserByName(String userName, Integer pageNum, Integer pageSize) {
        userName = "%"+userName+"%";
        PageHelper.startPage(pageNum,pageSize);
        List<SalenetUser> userList = userMapper.queryAllUserList(userName);
        PageInfo<SalenetUser> pageInfo = new PageInfo<>(userList);
        return pageInfo;
    }

    /**
     * 修改用户信息
     * @param user
     * @return
     */
    @Override
    public Integer updateUserMessage(SalenetUser user) {
        //修改非空字段
        Integer updateResult = userMapper.updateByPrimaryKeySelective(user);
        return updateResult;
    }

    /**
     * 根据Id删除用户信息
     * @param userId
     * @return
     */
    @Override
    public Integer deleteUserByUserId(Integer userId) {
        Integer deleteUser = userMapper.deleteUserByUserId(userId);
        if(deleteUser == null){
            deleteUser = 0;
            return deleteUser;
        }
        return deleteUser;
    }
}
